//
//  TTMusicMyPageSixTableViewCell.m
//  TTMusic
//
//  Created by yanghuiyan on 16/3/31.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "TTMusicMyPageSixTableViewCell.h"
#import "TTMusicMyPageSixCollectionViewCell.h"

#define WIDTHCON self.contentView.bounds.size.width
#define HEIGHTCON self.contentView.bounds.size.height
@implementation TTMusicMyPageSixTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        
        _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        
        _layout.minimumLineSpacing = 0;
        _layout.minimumInteritemSpacing = 0;
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        self.collectionView = [[TTMusicBaseCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        
        [self.collectionView registerClass:[TTMusicMyPageSixCollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCellIdentifier"];
        self.collectionView.backgroundColor = [UIColor whiteColor];
        
        [self.contentView addSubview:self.collectionView];
        
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.frame = self.bounds;
    _layout.itemSize = CGSizeMake(WIDTHCON / 3, HEIGHTCON / 2);

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TTMusicMyPageSixCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCellIdentifier" forIndexPath:indexPath];
   
    cell.label.text = self.title[indexPath.item];
    
    cell.pic.image = [UIImage imageNamed:self.pic[indexPath.item]];

    return cell;
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"jump" object:@(indexPath.item)];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
